package com.groupbuying.sysconfig.controller;

import java.util.List;
import java.util.Map;

import com.groupbuying.sysconfig.dto.PCDDto;
import com.groupbuying.sysconfig.dto.TreeNode;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.groupbuying.sysconfig.domain.SysconfigAreaDO;
import com.groupbuying.sysconfig.service.SysconfigAreaService;
import com.groupbuying.sysconfig.utils.PageUtils;
import com.groupbuying.sysconfig.utils.Query;
import com.groupbuying.sysconfig.utils.R;

/**
 * 地区码表
 * 
 * @author ywxd
 * @email yuwenxiaodong@126.com
 * @date 2019-03-13 17:53:37
 */
 
@Controller
@RequestMapping("/area")
public class AreaController {
	@Autowired
	private SysconfigAreaService sysconfigAreaService;

	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("sysconfig:sysstoreAreaconfigArea:sysconfigArea")
	public PageUtils list(@RequestParam Map<String, Object> params){
		return sysconfigAreaService.areaList(params);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("sysconfig:sysconfigArea:add")
	public R save( SysconfigAreaDO sysconfigArea){
		if(sysconfigAreaService.save(sysconfigArea)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("sysconfig:sysconfigArea:edit")
	public R update( SysconfigAreaDO sysconfigArea){
		sysconfigAreaService.update(sysconfigArea);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("sysconfig:sysconfigArea:remove")
	public R remove( Integer areaid){
		if(sysconfigAreaService.remove(areaid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("sysconfig:sysconfigArea:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] areaids){
		sysconfigAreaService.batchRemove(areaids);
		return R.ok();
	}
	
}
